﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace IInject.Registration
{
	public class EnumerableContextRegistry : RegistryBase<IEnumerable<RegistryContext>>
	{
		public EnumerableContextRegistry(IContainer container) : base(container)
		{
		}

		public override bool Contains(Type type, string key)
		{
			return key == null && Contains(type);
		}

		public override RegistryContext Get(Type type, string key)
		{
			return null;
		}

        public override IEnumerable<RegistryContext> GetAll(Type type, string key)
		{
            if (key == null)
            {
                var results = Get(type);

                if (results != null)
                {
                    return results;
                }
            }
			
			return Enumerable.Empty<RegistryContext>();
		}

		public override bool Register(Type from, RegistryContext context)
		{
			return false;
		}

        public override bool Register(Type from, string key, IEnumerable<RegistryContext> contexts)
		{
			if (key == null && contexts.Count() > 0)
			{
				Add(from, contexts);
				return true;
			}

			return false;
		}
	}
}
